<html>
<head>
<meta charset="utf-8">
<script src="https://apis.google.com/js/client.js?onload=init"></script>
</head>
<body>

	<form action="javascript:void(0);">
		<h2>List Provincias</h2>
		<div>
			<input id="listQuote" type="submit" value="List Provincias">
		</div>
	</form>
	<div id="listQuotesResult"></div>

	<form action="javascript:void(0);">
		<h2>Insert New Provincia</h2>
		<div>
			<input id="txtAuthorName" placeholder="Author name here"></input>
		</div>
	
		<div>
			<input id="insertPartido" type="submit" value="Insertar Provincia">
		</div>
	</form>

	<form action="javascript:void(0);">
		<h2>Delete Provincia</h2>
		<div>
			<input id="quoteID" placeholder="Quote ID value"></input>
		</div>
		<div>
			<input id="deleteQuote" type="submit" value="Delete Provincia">
		</div>
	</form>


	<script type="text/javascript">
        function init() {
                //Parameters are APIName,APIVersion,CallBack function,API Root 
                gapi.client.load('provinciaendpoint', 'v1', null, 'https://robotapolar.appspot.com/_ah/api');
                
                document.getElementById('listQuote').onclick = function() {
                    listQuotes();
                  }
                
                document.getElementById('insertPartido').onclick = function() {
                        insertPartido();
                }
                
                
                document.getElementById('deleteQuote').onclick = function() {
                        deleteQuote();
                }
        }
        
        //List Quotes function that will execute the listQuote call
        function listQuotes() {
                gapi.client.provinciaendpoint.listProvincia().execute(function(resp) {
                        if (!resp.code) {
                                resp.items = resp.items || [];
                                var result = "";
                                for (var i=0;i<resp.items.length;i++) {
                                        result = result+ resp.items[i].name + "..." + "<b>" + resp.items[i].name + "</b>" + "[" + resp.items[i].id + "]" + "<br/>";
                                }
                                document.getElementById('listQuotesResult').innerHTML = result;
                        }
                });
        }
        
        //Insert Quote function
        function insertPartido() {
                //Validate the entries
                var _AuthorName = document.getElementById('txtAuthorName').value;
                
                //Build the Request Object
                var requestData = {};
                requestData.name = _AuthorName;
                gapi.client.provinciaendpoint.insertProvincia(requestData).execute(function(resp) {
                        if (!resp.code) {
                                //Just logging to console now, you can do your check here/display message
                                console.log(resp.name);
                        }
                });
        }
        
        //Delete Quote function
        function deleteQuote() {
                //Validate the entries
                var _ID = document.getElementById('quoteID').value;
                
                //Build the Request Object
                var requestData = {};
                requestData.id = _ID;
                console.log(requestData);
                gapi.client.provinciaendpoint.removeProvincia(requestData).execute(function(resp) {
                        //Just logging to console now, you can do your check here/display message
                        console.log(resp);
                });
        }
        
    </script>
	<script src="https://apis.google.com/js/client.js?onload=init"></script>

</body>
</html>